using SS;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace SM.core
{
	internal class Desease
	{
		private Func objFunc = new Func();
		public Desease()
		{
			Program.strConnectionString = this.objFunc.strConnectionString;
		}
		public int action(string ID, string Name, string Des)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("ActionOnTabDesease", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("ID", SqlDbType.Int);
				sqlCommand.Parameters.Add("Name", SqlDbType.NVarChar, 500);
				sqlCommand.Parameters.Add("Des", SqlDbType.NVarChar, 1500);
				sqlCommand.Parameters["ID"].Value = ID;
				sqlCommand.Parameters["Name"].Value = Name;
				sqlCommand.Parameters["Des"].Value = Des;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
		public void loadGridView(DataGridView dgv, BindingNavigator bdn)
		{
			dgv.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			string selectCommandText = "SELECT ID, Name, Des FROM [TabDesease] ORDER BY [Name]";
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommandText, sqlConnection);
			DataSet dataSet = new DataSet();
			sqlDataAdapter.Fill(dataSet);
			BindingSource bindingSource = new BindingSource();
			bindingSource.DataSource = dataSet.Tables[0];
			bdn.BindingSource = bindingSource;
			dgv.DataSource = bindingSource;
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		public int delItem(string ID)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				string cmdText = "DELETE [TabDesease] WHERE [ID] = " + ID;
				SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection);
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
	}
}
